/**
 * API路径配置文件
 * 统一管理所有API接口路径
 */

// API基础路径
export const API_BASE_URL = '/api'

// 各模块API路径前缀
export const API_PATHS = {
  // 通用模块
  COMMUNITY: '/community',
  BUILDING: '/building',
  ROOM: '/room',
  
  // 业主管理
  HOMEOWNER: '/homeowner',
  
  // 车辆管理
  CAR: '/car',
  
  // 设备管理
  EQUIPMENT: '/equipment',
  EQUIPMENT_MAINTENANCE: '/equipmentMaintenance',
  MAINTENANCE_RECORD: '/maintenanceRecord',
  MAINTENANCE_PLAN: '/maintenancePlan',
  
  // 供应商管理
  SUPPLIER: '/supplier',
  
  // 物料管理
  MATERIAL: '/material',
  
  // 库存管理
  INVENTORY: '/inventory',
  
  // 入库管理
  BOUND: '/bound',
  
  // 仓库管理
  WAREHOUSE: '/warehouse',
  
  // 账单管理
  BILL: '/bill'
}

// 通用API端点
export const COMMON_ENDPOINTS = {
  // 基础CRUD操作
  ALL: '/all',
  PAGE: '/page',
  ADD: '/add',
  UPDATE: '/update',
  DELETE: '/delete',
  DETAIL: '/detail',
  SEARCH: '/search',
  
  // 特殊操作
  BY_ID: '/byid',
  BY_STATUS: '/byStatus',
  BY_TYPE: '/byType',
  GENERATE_ID: '/generateId',
  GENERATE_CODE: '/generateCode',
  INIT_TEST_DATA: '/initTestData'
}

// 构建完整API路径的工具函数
export const buildApiPath = (module, endpoint = '') => {
  return `${API_PATHS[module]}${endpoint}`
}

// 构建带ID的API路径
export const buildApiPathWithId = (module, id, endpoint = '') => {
  return `${API_PATHS[module]}${endpoint}/${id}`
}

// 构建带参数的API路径
export const buildApiPathWithParams = (module, endpoint, params = {}) => {
  const basePath = `${API_PATHS[module]}${endpoint}`
  const queryString = Object.keys(params)
    .filter(key => params[key] !== undefined && params[key] !== null)
    .map(key => `${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`)
    .join('&')
  
  return queryString ? `${basePath}?${queryString}` : basePath
}

export default {
  API_BASE_URL,
  API_PATHS,
  COMMON_ENDPOINTS,
  buildApiPath,
  buildApiPathWithId,
  buildApiPathWithParams
}
